<template>
	<view>
		<form class="form_list">
			<view class="view-flex">
				<view class="item1">
					<button :roleid="1-roleid" @click="changeid1" class="changerole" :type="btn1type"
						:disabled="isDisable">普通用户</button>
				</view>
				<view class="item2">
					<button :roleid="roleid" @click="changeid2" class="changerole" :type="btn2type"
						:disabled="!isDisable">管理员</button>
				</view>
			</view>
			<view>
				<view v-show="1-roleid">
					<startframe :roleid="roleid" v-on:enter="enter"></startframe>
				</view>
				<view v-show="roleid">
					<startframe :roleid="roleid" @enter="enter"></startframe>
				</view>
			</view>
			<button type="primary" plain="true" @click="formsubmit"
				style="width: 70%;position: relative;left: 0rpx ;top: 50rpx;">注册</button>
			<navigator url="login" open-type="redirect" hover-class="other-navigator-hover">
				<text class="login">已有帐号？去登录...</text>
			</navigator>

		</form>
	</view>
</template>

<script>
	import axios from "../../utils/http.js";
import startframe from "../../component/userstartframe/userstartframe.vue"
	export default {
		components: {
			startframe,
		},
		data() {
			return {
				roleid: 0, //0表示显示普通用户，1表示管理员
				user: {
					userid: '',
					psword: '',
				},
				showPassword: true,
				btn1type: "primary",
				btn2type: "default",
				isDisable: true
			}
		},
		methods: {
			changeid1: function() {
				this.isDisable = true;
				this.btn1type = "primary";
				this.btn2type = "default";
				return this.userid = 0;
			},
			changeid2: function() {
				this.isDisable = false;
				this.btn1type = "default";
				this.btn2type = "primary";
				return this.userid = 1;
			},
			enter: function(val) {
				this.user = val;
			},
			formsubmit: function() {
				axios({
					method: 'POST',
					url: '/smartAttendance/index/register',
					header: {
						//返回数据类型
						"content-type": " application/json; charset=utf-8",
						//设置用户访问的token信息
						"Authorization": '请求头信息',
					},
					data: {
						user: this.user,
					}
				}).then(res => {
					console.log(axios.header)
					console.log(res.data) 
					console.log(this.user)
					if (res.data == true) {
						uni.redirectTo({
							url: '/pages/login/login'
						})
					}

				}, error => {
					console.log('err', error.message)
				})

			},
		},
	}
</script>

<style scoped>
	.form_list {
		top: 20%;
		bottom: -20%;
		height: 712rpx;
		width: 100%;
		position: absolute;
		display: block;
		box-sizing: border-box;
	}

	.item1 {
		display: inline-block;
		width: 50%;
	}

	.item2 {
		display: inline-block;
		width: 50%;
	}

	.changerole {
		position: relative;
		left: 0 rpx;
		top: -54rpx;
	}

	.view-flex {
		display: flex;
		flex-direction: row;
		justify-content: center;
	}

	.login {
		position: relative;
		text-align: center;
		left: 30%;
		top: 347rpx;
	}
</style>